/**
 * Project Name:UIMS
 * File Name:SysLoginlogAction.java
 * Package Name:com.bgi.uims.module.sys.loginlog.action
 * CreateDate:2015年3月20日 下午2:09:52
 * Copyright (c) 2015, BGI_DX All Rights Reserved.
 */     

package com.bgi.uims.module.sys.loginlog.action;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.bgi.uims.common.action.BaseAction;
import com.bgi.uims.common.dto.PageVo;
import com.bgi.uims.module.sys.loginlog.dto.SysLoginlog;
import com.bgi.uims.module.sys.loginlog.service.SysLoginlogService;
import com.bgi.uims.pub.utils.Constant;
import com.bgi.uims.pub.utils.PublicMethod;

/**
 * ClassName:SysLoginlogAction 
 * Function: TODO 
 * Reason:	 TODO 
 * @CreateDate:2015年3月20日 下午2:09:52
 * @author   tantianhua
 * @version  
 * @since    JDK 1.7
 * @see 	 
 */
@Controller
@Scope("prototype")
public class SysLoginlogAction extends BaseAction {
	
	/**  
	 * serialVersionUID:TODO（用一句话描述这个变量表示什么）  
	 */   
	private static final long serialVersionUID = -700919983611115341L;

	private PageVo pageVo = new PageVo();
	
	private SysLoginlog loginlog;
	
	@Resource
	private SysLoginlogService sysLoginlogService;

	public PageVo getPageVo() {
		return pageVo;
	}

	public void setPageVo(PageVo pageVo) {
		this.pageVo = pageVo;
	}

	public SysLoginlog getLoginlog() {
		return loginlog;
	}

	public void setLoginlog(SysLoginlog loginlog) {
		this.loginlog = loginlog;
	}
	
	/**
	 * 
	 * @Description：  查询日志信息
	 * @author: tantianhua
	 * @CreateDate:2015年3月20日 下午2:09:52
	 * @version: V1.0
	 */
	public String queryLoginlog() {
		if (loginlog == null) {
			loginlog = new SysLoginlog();
		}
		loginlog.getPage(this);
		pageVo = sysLoginlogService.queryLoginlog(loginlog);
		List<SysLoginlog> loginlogs = pageVo.getRows();
		for(SysLoginlog loginlog:loginlogs){
			String onlineTimeStr = loginlog.getOnlineTime();
			if(onlineTimeStr != null){
				String lastOnlineTimeStr = "";
				Integer onlineTimeInt = Integer.parseInt(onlineTimeStr);
				if(onlineTimeInt/(24*60*60) > 0){
					lastOnlineTimeStr += onlineTimeInt/(24*60*60)+"天";
					onlineTimeInt = onlineTimeInt - ((onlineTimeInt/(24*60*60))*24*60*60);
				}
				if(onlineTimeInt/(60*60) > 0){
					lastOnlineTimeStr += onlineTimeInt/(60*60)+"小时";
					onlineTimeInt = onlineTimeInt - ((onlineTimeInt/(60*60))*60*60);
				}
				if(onlineTimeInt/60 > 0){
					lastOnlineTimeStr += onlineTimeInt/60+"分";
					onlineTimeInt = onlineTimeInt - ((onlineTimeInt/60)*60);
				}
				if(onlineTimeInt > 0){
					lastOnlineTimeStr += onlineTimeInt+"秒";
				}
				loginlog.setOnlineTime(lastOnlineTimeStr);
			}
			
		}
		session.put(Constant.OPERATIONMSG, PublicMethod.operationMsg(Constant.SELECT,Constant.LOGINLOGMODULES,loginlog, null));
		pageVo.setSuccess(true);
		return SUCCESS;
	}
}
